package com.atues.thread.syn;

import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;

public class TestJuc {
    public static void main(String[] args) throws InterruptedException {
        CopyOnWriteArrayList list = new CopyOnWriteArrayList();
        ArrayList<String> list1 = new ArrayList<>();

        for (int i = 0 ; i < 100; i++) {//这里用list的话就会可能导致size没有1000
            new Thread(() -> {
                list1.add(Thread.currentThread().getName());
            }).start();
            Thread.sleep(20);
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
//        System.out.println(list.size());//1000
        System.out.println(list1.size());
    }
}
